/*
 * File name: cgi_common.h
 * Description: Common definitions for cgi related codes of CMU serials
 */
 
#ifndef __CGI_COMMON_H__
#define __CGI_COMMON_H__

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <assert.h>
#include <math.h>
#include <unistd.h>

#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>


#define CGI_INTF_PORT			9978
#define CGI_PACK_MAX_LEN		102400
#define CGI_PACK_HEAD_LEN		3
#define CGI_PACK_VERSION_LEN	1
#define CGI_PACK_LENGTH			2
#define CGI_PACK_CMD_LEN		2
#define CGI_PACK_CRC_LEN		4
#define CGI_PACK_LEAST_LEN		(CGI_PACK_HEAD_LEN + CGI_PACK_VERSION_LEN + CGI_PACK_LENGTH + CGI_PACK_CMD_LEN + CGI_PACK_CRC_LEN)

#define CGI_PACK_HEAD_1						0x43 //'C'
#define CGI_PACK_HEAD_2						0x47 //'G'
#define CGI_PACK_HEAD_3						0x49 //'I'
#define CGI_PACK_VERSION					0x10	// 1.0
#define CGI_CMD_SOCK_ERROR					0xFFFE
#define CGI_CMD_NOT_SUPPORT					0xFFFF


#define CGI_CMD_GET_NETWORK					0x0111
#define CGI_CMD_GET_NETWORK_RET				0x0112
#define CGI_CMD_GET_SYSTEM					0x0113
#define CGI_CMD_GET_SYSTEM_RET				0x0114
#define CGI_CMD_GET_CONFIGURE				0x0115
#define CGI_CMD_GET_CONFIGURE_RET			0x0116
#define CGI_CMD_GET_DEVICE					0x0121
#define CGI_CMD_GET_DEVICE_RET				0x0122
#define CGI_CMD_GET_TEMPERATURE				0x0123
#define CGI_CMD_GET_TEMPERATURE_RET			0x0124
#define CGI_CMD_GET_STATUS					0x0125
#define CGI_CMD_GET_STATUS_RET				0x0126
#define CGI_CMD_GET_CURRENT_INFO			0x012B
#define CGI_CMD_GET_CURRENT_INFO_RET		0x012C
#define CGI_CMD_GET_ALARM_INFO				0x0131
#define CGI_CMD_GET_ALARM_INFO_RET			0x0132
#define CGI_CMD_GET_PING_ADDR				0x0139
#define CGI_CMD_GET_PING_ADDR_RET			0x013A
//-------------------------------------------------
#define CGI_CMD_SET_CONFIGURE				0x020A
#define CGI_CMD_SET_CONFIGURE_RET			0x020B
#define CGI_CMD_SET_NETWORK					0x020C
#define CGI_CMD_SET_NETWORK_RET				0x020D
#define CGI_CMD_LOAD_DEFAULT				0x020E
#define CGI_CMD_LOAD_DEFAULT_RET			0x020F
#define CGI_CMD_CLEAR_ALARM_INFO			0x021A
#define CGI_CMD_CLEAR_ALARM_INFO_RET		0x021B
#define CGI_CMD_LOGIN						0x021C
#define CGI_CMD_LOGIN_RET					0x021D
#define CGI_CMD_APPLY_ACCOUNT				0x021E
#define CGI_CMD_APPLY_ACCOUNT_RET			0x021F
#define CGI_CMD_PING_TEST					0x0220
#define CGI_CMD_PING_TEST_RET				0x0221
#define CGI_CMD_APPLY_WIFI					0x0222
#define CGI_CMD_APPLY_WIFI_RET				0x0223

#define CGI_IP_LEN							32
#define CGI_PASSWORD_LEN					100
#define CGI_COMMON_LEN						128
#define CGI_LINE_LENGTH						256

#define ALARM_INFO_LINE_NUMBER				20
#define ALARM_INFO_COL_NUMBER				128

enum CGI_OUTPUT_START_SETTING
{
	CGI_OUTPUT_FALSE,
	CGI_OUTPUT_TRUE,
};

enum CGI_OUTPUT_PROTOCOL_SETTING
{
	CGI_TS_OUTPUT_PROTOCOL,
	CGI_PES_OUTPUT_PROTOCOL,
	CGI_RTMP_OUTPUT_PROTOCOL,
};

enum CGI_STREAM_CONNECTED_SETTING
{
	CGI_STREAM_STOP,
	CGI_STREAM_CONNECTED,
};

enum CGI_IP_RECEIVER_MODE_SETTING
{
	CGI_IP_RECEIVER_MODE_UNICAST,
	CGI_IP_RECEIVER_MODE_MULTICAST,
};


enum CONFIGURE_RET_SETTING
{
	CONFIGURE_CGI_RET_OK,
	CONFIGURE_CGI_RET_FAIL,
};

enum NETWORK_RET_SETTING
{
	NETWORK_CGI_RET_OK,
	NETWORK_CGI_RET_FAIL,
};

enum CGI_DECODE_STATUS_SETTING
{
	DECODE_STATUS_ERROR,
	DECODE_STATUS_RUNNING,
	DECODE_STATUS_STOP,
};

enum CGI_DEFAULT_INTERFACE_SETTING
{
	DEFAULT_INTERFACE_IP1 = 1,
	DEFAULT_INTERFACE_IP2,
};

enum CGI_LOGIN_SETTING
{
	DATETIME_CGI_LOGIN_FAIL,
	DATETIME_CGI_LOGIN_OK,
};

#endif


